cloth(dresses, dress1, darkBlue, short, summer,[pois],overall).
cloth(dresses, dress2, grey, long, winter,[patterned],overall).
cloth(dresses, dress3, orange, medium, summer,[],overall).
cloth(dresses, dress4, camel, long, midseason,[stripes],overall).
cloth(dresses, dress5, black, short, midseason,[studs],overall).

cloth(overcoats,overcoat1,black,medium,winter,[],coat).
cloth(overcoats,overcoat2,cream,long,winter,[chest],coat).
cloth(overcoats,overcoat3,black,short,winter,[],coat).

cloth(jackets,jacket1,blue,medium,midseason,[],coat).
cloth(jackets,jacket2,black,short,midseason,[],coat).
cloth(jackets,jacket3,jeans,short,midseason,[],coat).

cloth(sweaters,sweater1,yellow,long,winter,[buttons],top).
cloth(sweaters,sweater2,pink,long,winter,[pois],top).
cloth(sweaters,sweater3,green,long,winter,[cardigan,buttons],top).
cloth(sweaters,sweater4,brown,long,winter,[],top).
cloth(sweaters,sweater5,white,long,winter,[],top).

cloth(blouses,blouse1,fuchsia,long,midseason,[buttons],top).
cloth(blouses,blouse2,violet,medium,midseason,[zip],top).
cloth(blouses,blouse3,navy,long,midseason,[design],top).
cloth(blouses,blouse4,khaki,medium,midseason,[ribbon,stripes],top).
cloth(blouses,blouse5,coral,long,midseason,[animalprint],top).

cloth(tops,top1,beige,long,midseason,[],top).
cloth(tops,top2,white,short,summer,[],top).
cloth(tops,top3,salmon,medium,midseason,[pois],top).
cloth(tops,top4,peach,short,summer,[],top).
cloth(tops,top5,lime,long,midseason,[],top).

cloth(tshirts,tshirt1,black,short,summer,[ribbon],top).
cloth(tshirts,tshirt2,olive,short,summer,[lace],top).
cloth(tshirts,tshirt3,cream,short,summer,[ethnic],top).
cloth(tshirts,tshirt4,red,short,summer,[picture],top).
cloth(tshirts,tshirt5,beige,short,summer,[ribbon.lace],top).

cloth(trousers,trousers1,jeans,long,midseason,[studs],bottom).
cloth(trousers,trousers2,black,long,allseasons,[suit],bottom).
cloth(trousers,trousers3,darkBlue,long,summer,[linen,flower],bottom).
cloth(trousers,trousers4,red,long,midseason,[stretch],bottom).
cloth(trousers,trousers5,brown,long,allseasons,[skinny],bottom).

cloth(skirts,skirt1,darkGrey,medium,midseason,[pencil],bottom).
cloth(skirts,skirt2,black,long,midseason,[maxi],bottom).
cloth(skirts,skirt3,green,short,summer,[stretch],bottom).
cloth(skirts,skirt4,blue,short,winter,[],bottom).
cloth(skirts,skirt5,jeans,short,allseason,[],bottom).
cloth(skirts,skirt6,yellow,short,winter,[],bottom).

cloth(suits,suit1,darkGrey,long,midseason,[],overall).
cloth(suits,suit2,black,long,winter,[],overall).

cloth(shoes,shoes1,black,high,midseason,[zip],footwear).
cloth(shoes,shoes2,grey,high,allseasons,[],footwear).
cloth(shoes,shoes3,red,medium,allseasons,[],footwear).
cloth(shoes,shoes4,beige,flat,summer,[studs],footwear).
cloth(shoes,shoes5,brown,flat,midseason,[ballet],footwear).

cloth(boots,boots1,black,high,winter,[],footwear).
cloth(boots,boots2,brown,medium,midseason,[],footwear).
cloth(boots,boots3,yellow,high,winter,[],footwear).

cloth(sportshoes,sportshoes1,white,flat,summer,[],footwear).
cloth(sportshoes,sportshoes2,black,flat,allseasons,[],footwear).

categories([dresses,overcoats,jackets,sweaters,blouses,tops,tshirts,trousers,skirts,suits,shoes,boots,sportshoes]).

delete_sub_list([H|T],L,Z):- delete(H,L,FL), delete_sub_list(T,FL,Z).
delete_sub_list([],L,L).

%exclude
category_filter_exclude([H|T]) :- retractall(cloth(H,_,_,_,_,_,_)),!, category_filter_exclude(T).
category_filter_exclude([H|T]):- category_filter_exclude(T).
category_filter_exclude([]).
%include _only
retract_categories([H|T]) :- retractall(cloth(H,_,_,_,_,_,_)),  retract_categories(T).
retract_categories([]).
category_filter_include(IncludeList,AllCategories):-  	delete_sub_list(IncludeList,AllCategories,CatList), 
							retract_categories(CatList).
							
%category_filter(general) :- !, category_filter_exclude([boots]).		
%category_filter(sweaters) :- !, category_filter_exclude([jackets]).
%category_filter(shirt) :- !, category_filter_include([jackets, boots], [dresses, shirt, boots, jackets]).
%category_filter(general) :- !, category_filter_include([jackets, boots], [dresses, shirt, boots, jackets]).

category_filter(general):- !,categories(L), category_filter_include([tops, trousers, shoes],L).
category_filter(dresses) :- !, category_filter_exclude([boots,sportshoes]).
category_filter(_).

attributes_filter(tops,N,C,medium,_,EL):- !, member(pois, EL), C\=white.
attributes_filter(trousers,N,jeans,long,_,EL):- !, member(studs, EL).
attributes_filter(shoes,N,black,high,_,EL):- !, member(zip, EL).
attributes_filter(dresses,N,C,short,_,_):- !, cloth(dresses, N, Color,_,_,_, _),member(Color, [yellow, black, darkBlue, darkGray, brown]).

%devono esserci per tutte la categorie che non hanno filtri specificati
attributes_filter(jackets, _, _, _, _, _).
attributes_filter(skirts, _, _, _, _, _).


%attributes_filter(sweaters, N, yellow, _, _, _).
%attributes_filter(sweaters, _, _, _, _, _).
%attributes_filter(skirts, _, _, _, _, _).
%attributes_filter(boots, _, _, _, _, _).
%attributes_filter(shoes, _, _, _, _, _).
%attributes_filter(tops, N, white, _, _, _) :- !, fail. 
%attributes_filter(tops, N, _, medium, _, _) :- !.
%attributes_filter(tops, N, _, _, _, pois) :- !, cloth(_,N,_,_,_,EL), member(E, EL). 

%attributes_filter(_, _, _, _, _, _).

%list_filter(sweaters, N,color) :- !, cloth(_, N, Color,_,_,_, _), member(Color, [yellow, black, darkBlue, darkGray, brown]).
%list_filter(dresses, N, len) :- !, cloth(_, N, _,Length,_,_, _), not(member(Length, [black, darkBlue, darkGray, brown])).

%list_filter(_, _, _).


call_filter(Cat, _, Co, L, S, E, N1, N2) :- condition(Cat, _, Co, L, S, E), !, then(Cat, _, Co, L, S, E, N1, N2).					
call_filter(Cat, _, Co, L, S, E, N1, N2) :- else(Cat, _, Co, L, S, E, N1, N2).
call_filter(Cat, _, Co, L, S, E, N1, N2).

filter(FList, N1, N2) :- 	assert_temp_filter(FList),
				bagof(C, bubolo(C,_,_,_,_,_), L),
				%write(L),
				categories(CA),
				delete_sub_list(L,CA,LO),
				assert_others_temp(LO),
				%write(L2),
				cloth(C1, N1, Co1, L1, S1, E1, _),
				cloth(C2, N2, Co2, L2, S2, E2, _),
				bubolo(C1, N1, Co1, L1, S1, E1),
				bubolo(C2, N2, Co2, L2, S2, E2),
				!,
				bagof(X, retract(bubolo(X,_,_,_,_,_)), L3).
				
filter(FList, N1, N2) :- bagof(X, retract(bubolo(X,_,_,_,_,_)), L3), fail.
		
assert_others_temp([H|T]) :- asserta(bubolo(H, _, _, _, _, _)), assert_others_temp(T).
assert_others_temp([]).
						
assert_temp_filter([H|T]) :- asserta(H), assert_temp_filter(T).
assert_temp_filter([]).

%bubolo(_, _, _, _, _, _).


%call_temp_filter(C, N, Co, L, S, E) :- 	temp_attributes_filter(C, N, Co, L, S, E), 
%					retract(temp_attributes_filter(C, N, Co, L, S, E)), !.
%call_temp_filter(C, N, Co, L, S, E) :- 	retract(temp_attributes_filter(C, N, Co, L, S, E)).

 
%condition(sweaters, _, _, long, _, _).

%then(sweaters, _, _, long, _, _, N1, N2) :- filter([bubolo(skirts, _, yellow, short, _, _)], N1, N2).
%else(sweaters, _, _, long, _, _, N1, N2).

condition(dresses,_,_,long,_,_).
then(dresses, _, _, long, _, _, N1, N2) :- filter([bubolo(jackets, _,_, short, _, _),bubolo(jackets, _,_, short, _, _)], N1, N2).
else(dresses, _, _, long, _, _, N1, N2).


createOutfit(Season, N1, N2, N3) :-	category_filter(general),
					cloth(C1, N1, CO1, L1, Season, E1, coat), 
					cloth(C2, N2, CO2, L2, Season, E2, overall), 
					cloth(C3, N3, CO3, L3, Season, E3, footwear),
					write(N1),
					category_filter(C1),
					category_filter(C2),
					category_filter(C3),
					
					attributes_filter(C1, N1, CO1, L1, Season, E1),
					attributes_filter(C2, N2, CO2, L2, Season, E2),
					attributes_filter(C3, N3, CO3, L3, Season, E3),
					call_filter(C1, _, CO1, L1, Season, E1, N2, N3),
					call_filter(C2, _, CO2, L2, Season, E2, N1, N3),
					call_filter(C3, _, CO3, L3, Season, E3, N1, N2). 